<?php

class m120204_094735_material_stats extends CDbMigration {
	public function safeUp() {
		$this->addColumn('erp_user_access', 'materialViewProject', 'boolean');
		$this
			->insert('erp_auth_item',
				array(
					'name' => 'materialViewProject',
					'type' => CAuthItem::TYPE_ROLE,
					'bizrule' => 'return AccessControl::check("materialViewProject");',
				));
		$this
			->insert('erp_auth_item_child',
				array(
					'parent' => 'employee',
					'child' => 'materialViewProject',
				));
	}

	public function safeDown() {
		$this
			->delete('erp_auth_item_child',
				array(
					'and',
					'parent=:parent',
					'child=:child',
				),
				array(
					':parent' => 'employee',
					':child' => 'materialViewProject',
				));
		$this
			->delete('erp_auth_item', 'name=:name',
				array(
					':name' => 'materialViewProject',
				));
		$this->dropColumn('erp_user_access', 'materialViewProject');
	}
}
